// opentest <problemid> <testid>

#include <iostream>
#include <direct.h>
#include <fstream>
#include <cstdlib>
#include <string>
#include <io.h>

using namespace std;

string quote(const string & s)
{
    return "\"" + s + "\"";
}

int main(int argc, char* argv[])
{
    if (argc != 3)
    {
        puts("opentest <problemid> <testid>");
        return 1;
    }

    string problemid = argv[1];
    string testid = argv[2];
    string pwd = getcwd(NULL, 0);

    system(quote(pwd + "\\data\\" + problemid + "\\" + testid + ".in").c_str());
    string anspath = pwd + "\\data\\" + problemid + "\\" + testid + ".out";
    if (_access(anspath.c_str(), 0) == -1)
    {
        anspath = pwd + "\\data\\" + problemid + "\\" + testid + ".ans";
        if (_access(anspath.c_str(), 0) == -1)
        {
            cout << "Please enter answer file suffix for the test point " << testid << ": ";
            string ans_suffix;
            cin >> ans_suffix;
            anspath = pwd + "\\data\\" + problemid + "\\" + testid + "." + ans_suffix;
            if (_access(anspath.c_str(), 0) == -1)
            {
                cout << "Unable to find the answer file for the test point " + testid << endl;
                return 1;
            }
        }
    }
    system(quote(anspath).c_str());
    system(quote(pwd + "\\problems\\" + problemid + "\\" + testid + ".out").c_str());

    return 0;
}
